package flc.ast.adapter;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyCropBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class CropAdapter extends StkProviderMultiAdapter<MyCropBean> {

    public CropAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(75));
        addItemProvider(new CropProvider());
    }

    private class CropProvider extends BaseItemProvider<MyCropBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_crop;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyCropBean bean) {
            if (baseViewHolder.getBindingAdapterPosition() == 0) {
                baseViewHolder.getView(R.id.llFreeCropItem).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.llCropItem).setVisibility(View.GONE);
                baseViewHolder.setText(R.id.tvFreeCropItemName, bean.getName());
                baseViewHolder.setText(R.id.tvFreeCropItemText, bean.getText());
                if (bean.isSelect()) {
                    baseViewHolder.setBackgroundColor(R.id.llFreeCropItem, Color.parseColor("#4E70EF"));
                } else {
                    baseViewHolder.setBackgroundColor(R.id.llFreeCropItem, Color.parseColor("#12172D"));
                }
            } else {
                baseViewHolder.getView(R.id.llFreeCropItem).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.llCropItem).setVisibility(View.VISIBLE);
                baseViewHolder.setText(R.id.tvCropItemName, bean.getName());
                baseViewHolder.setText(R.id.tvCropItemText, bean.getText());
                if (bean.isSelect()) {
                    baseViewHolder.setBackgroundColor(R.id.llCropItem, Color.parseColor("#4E70EF"));
                } else {
                    baseViewHolder.setBackgroundColor(R.id.llCropItem, Color.parseColor("#12172D"));
                }
            }
        }
    }
}
